package com.example.springbootlinmtest.controller;

import com.alibaba.excel.EasyExcel;
import com.example.springbootlinmtest.pojo.LogConcat;
import com.example.springbootlinmtest.pojo.UserInfo;
import com.example.springbootlinmtest.service.LogConcatService;
import com.example.springbootlinmtest.utils.UploadDataListener;
import com.example.springbootlinmtest.utils.analyzeUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Linm
 * @Date 2023/4/1 20:53
 */
@Controller
@Slf4j
public class UserInfoController {

    @Resource
    private LogConcatService logConcatService;

    @PostMapping("/unUsed")
    @ResponseBody
    public HashMap<String, Object> upload(MultipartFile file) throws IOException {
        UploadDataListener listener = new UploadDataListener();
        EasyExcel.read(file.getInputStream(), UserInfo.class, listener).sheet().doRead();
        List<UserInfo> excelList = listener.excelList();
        analyzeUtil.analyze(excelList);
        return null;
    }


    @PostMapping("/upload")
    @ResponseBody
    public Map<String, Map<String, Object>> analyzeExcel(MultipartFile file) throws IOException {
        UploadDataListener listener = new UploadDataListener();
        EasyExcel.read(file.getInputStream(), UserInfo.class, listener).sheet().doRead();
        List<UserInfo> excelList = listener.excelList();
        return analyzeUtil.analyze(excelList);
    }
    @PostMapping("/11")
    @ResponseBody
    public String test(String file)  {
        LogConcat logConcat = new LogConcat();
        logConcat.setException("ee");
        logConcat.setIp("127.0.0.1");
        logConcat.setParams("test");
        logConcat.setResult("false");
        logConcat.setUsername("linm");
        logConcat.setUrl("lll");
        logConcat.setId(1L);
        //logConcatService.insert(logConcat);
        return "qq";
    }

}
